package com.hexinfo.dmpro.admin.config;

import com.hexinfo.dmpro.common.utils.SecurityUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Zheng Jie
 */
@Service(value = "permission")
public class PermissionConfig {

    public Boolean check(String ...permissions){
        // 获取当前用户的所有权限
        List<String> permission = SecurityUtils.getUserDetails().getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
        // 判断当前用户的所有权限是否包含接口上定义的权限
        return permission.contains("admin") || Arrays.stream(permissions).anyMatch(permission::contains);
    }
}
